using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShadowSpire : MonoBehaviour
{
    // Start is called before the first frame update
    private Transform Player;

    private SpriteRenderer thisSprite, playerSprite;
    
    private Color color;
    
    [Header("时间控制参数")]
    public float activeTime;
    public float activeStart;

    [Header("不透明度控制")]
    private float alpha;

    public float alphaSet; //初始值

    public float alphaMultipler;
    
    private void OnEnable() {
      Player = GameObject.FindGameObjectWithTag("Player").transform;
      thisSprite = GetComponent<SpriteRenderer>();
      playerSprite = Player.GetComponent<SpriteRenderer>();

      alpha = alphaSet;

      //复制player transform 信息
      thisSprite.sprite = playerSprite.sprite;
      transform.position = Player.position;
      transform.localScale = Player.localScale;
      transform.rotation = Player.rotation;

      activeStart = Time.time; 
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        alpha *= alphaMultipler;

        color = new Color(0.5f,0.5f,1, alpha);

        thisSprite.color = color;

        if(Time.time>= activeStart+activeTime){
          //返回对象池 
          ShadowPool.instance.ReturnPool(gameObject);
        }
    }
}
